<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*"%>
<%@ page import="org.apache.ibatis.*"%>
<%
	request.setCharacterEncoding("utf-8");
%>
<%
	String id = request.getParameter("userid");

	String pw = request.getParameter("passwd");
	String errMsg = "";

	if (id == null) {
		id = "";
		pw = "";	
	} else {
		User user = RentalHome.getUser(id);
		Manager manager = RentalHome.getManager(id);
		if (user == null && manager==null)
			errMsg = "잘못된 아이디 입니다.";
		else if (user !=null && !pw.equals(user.get비밀번호()))
			errMsg = "잘못된 비밀번호 입니다.";
		else if(manager !=null && !pw.equals(manager.get비밀번호()))
			errMsg = "잘못된 비밀번호 입니다.";
		else if(user !=null && pw.equals(user.get비밀번호())){
			response.sendRedirect("./Filterable/Main.jsp?id="+id);
			session.setAttribute("user", user);
			session.setAttribute("userID", id);
			String userRank = user.get사용자직급();
			session.setAttribute("userRank", userRank);
			String userName = user.get이름();
			session.setAttribute("userName", userName);
			String userDepart = user.get학과이름();
			session.setAttribute("userDepart", userDepart);
			return;
		}
		else{
			response.sendRedirect("./Filterable/Main.jsp?id="+id);
			session.setAttribute("manager", manager);
			session.setAttribute("managerID", id);
			String managerRank = manager.get직원직급();
			session.setAttribute("managerRank",managerRank);
			String managerName = manager.get이름();
			session.setAttribute("managerName",managerName);
			return;
		}
	}
%>
<html>
<head>
<!-- Bootstrap -->
<script src="./bootstrap/js/bootstrap.js"></script>
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet"
	media="screen">
<meta http-equiv="Content-Type" content="text/html; charset=uft-8">
<title>성공회대학교 기자재대여시스템</title>

</head>
<body style="background:#FFFFFF url(./img/back.jpg) no-repeat fixed right bottom"><p>
<p align="center">
<br><br><br><br><br><br><br><br><br>
	<table>
		<tr>
			<td><img src="./img/logo.jpg"
				style="width: 310px; height: 120px;"></td>
		</tr>
		<tr>
			<td>
				<form name="login"  method="POST">
					<label for="textinput1">아이디</label> <input name="userid"
						type="text" name="a" maxlength="10" value="<%=id%>" /><BR> <label
						for="textinput2"> 비밀번호</label> <input name="passwd"
						type="password" maxlength="10" value="<%=pw%>" />
			</td>
		</tr>
		<tr>
		
			<td ><font color="red"> <%=errMsg%></font><br><input class="btn btn-inverse" type="submit" value="로그인"
				name="submit" style="width: 70; "/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="./Sjoin.jsp" class="btn-link btn-small" style="width: 50">학생등록</a>
				<a href="./Pjoin.jsp" class="btn-link btn-small" style="width: 50">교수등록</a>
				<a href="./Mjoin.jsp" class="btn-link btn-small" style="width: 50">직원등록</a>
			</form> 
			
			</td>
		</p>
	</table>
	</p>
	<form method="post" action="Header.jsp?id2=id"></form>
</body>
</html>